| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 1 | Gerrit2 - Installation |
| 2 | ====================== |
| 3 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 4 | You need a SQL database to house the Gerrit2 metadata. Currently |
| 5 | PostgreSQL is the only supported database. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 6 | |
| 7 | Important Links |
| 8 | --------------- |
| 9 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 10 | PostgreSQL: |
| 11 | |
| 12 | * http://www.postgresql.org/docs/[Documentation] |
| 13 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 14 | Downloading Gerrit |
| 15 | ------------------ |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 16 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 17 | Current and past binary releases of Gerrit can be obtained from |
| 18 | the downloads page at the project site: |
| 19 | |
| 20 | * http://code.google.com/p/gerrit/downloads/list[Gerrit Downloads] |
| 21 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 22 | Download any current `*.war` package. |
| 23 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 24 | |
| 25 | Building Gerrit From Source |
| 26 | --------------------------- |
| 27 | |
| 28 | Alternatively, you can build the application distribution using |
| 29 | Maven from a source download obtained directly from Git: |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 30 | |
| 31 | ==== |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 32 | mkdir gerrit2 |
| 33 | cd gerrit2 |
| 34 | repo init -u git://android.git.kernel.org/tools/manifest.git |
| 35 | |
| 36 | (cd jgit/jgit-maven/jgit && mvn install) |
| Shawn O. Pearce | b951af1 | 2009-02-06 12:32:18 -0800 | [diff] [blame] | 37 | (cd sshd && mvn install) |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 38 | |
| Shawn O. Pearce | 263786e | 2009-02-02 15:49:26 -0800 | [diff] [blame] | 39 | mvn clean package |
| 40 | cp target/gerrit-*.war ...YOUR.DEST.../gerrit.war |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 41 | ==== |
| 42 | |
| 43 | The first build may take a while as dependencies are searched |
| 44 | for and downloaded from Maven distribution repositories. |
| 45 | |
| Shawn O. Pearce | b951af1 | 2009-02-06 12:32:18 -0800 | [diff] [blame] | 46 | Unfortunately you need to install snapshots of both JGit and |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 47 | SSHD to your local Maven repository (typically under `~/.m2`). |
| 48 | These core dependencies are still under active development and have |
| 49 | not made final releases yet. |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 50 | |
| 51 | Apache Maven: |
| 52 | |
| 53 | * http://maven.apache.org/download.html[Download] |
| 54 | * http://maven.apache.org/run-maven/index.html[Running Maven] |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 55 | |
| Shawn O. Pearce | b951af1 | 2009-02-06 12:32:18 -0800 | [diff] [blame] | 56 | Apache SSHD: |
| 57 | |
| 58 | * http://mina.apache.org/sshd/[Apache SSHD] |
| 59 | |
| 60 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 61 | Setting up the Database |
| 62 | ----------------------- |
| 63 | |
| 64 | Currently PostgreSQL is the only supported database. H2 may also |
| 65 | work, but hasn't been tested in a while. The primary concern is |
| 66 | having support for the database in the gworm project. |
| 67 | |
| 68 | PostgreSQL |
| 69 | ~~~~~~~~~~ |
| 70 | |
| 71 | Create a Gerrit specific user as a normal user (no superuser access) |
| 72 | and assign it an encrypted password: |
| 73 | |
| 74 | ==== |
| 75 | createuser -A -D -P -E gerrit2 |
| 76 | ==== |
| 77 | |
| 78 | Create the database to store the Gerrit metadata, and set the user |
| 79 | you just created as the owner of that database: |
| 80 | |
| 81 | ==== |
| 82 | createdb -E UTF-8 -O gerrit2 reviewdb |
| 83 | ==== |
| 84 | |
| 85 | Initialize the Schema |
| 86 | --------------------- |
| 87 | |
| 88 | Create the Gerrit 2 Tables |
| 89 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 90 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 91 | Either run CreateSchema from the command line: |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 92 | |
| 93 | ==== |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 94 | java -jar gerrit.war --cat extra/GerritServer.properties_example >GerritServer.properties |
| 95 | edit GerritServer.properties |
| 96 | |
| 97 | java -jar gerrit.war CreateSchema |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 98 | ==== |
| 99 | |
| 100 | Or, run the application once in a container to force it to initialize |
| 101 | the database schema before accessing it. (See below for deployment |
| 102 | setup documentation.) If you use this approach, it is recommended |
| 103 | that you stop the application before continuing with the setup. |
| 104 | |
| 105 | Add Indexes |
| 106 | ~~~~~~~~~~~ |
| 107 | |
| 108 | A script should be run to create the query indexes, so Gerrit |
| 109 | can avoid table scans when looking up information. Run the |
| 110 | `sql/query_index.sql` script through your database's query tool. |
| 111 | |
| 112 | e.g. with PostgreSQL: |
| 113 | |
| 114 | ==== |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 115 | java -jar gerrit.war --cat sql/query_index.sql | psql reviewdb |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 116 | ==== |
| 117 | |
| 118 | Configure site_path |
| 119 | ~~~~~~~~~~~~~~~~~~~ |
| 120 | |
| 121 | This directory holds server-specific configuration files and |
| 122 | assets used to customize the deployment. Gerrit needs read |
| 123 | access (but not write access) to the directory. The path |
| 124 | is stored in `system_config.site_path`, so you will need to |
| 125 | update the database with this value. |
| 126 | |
| 127 | ==== |
| 128 | mkdir /home/gerrit/cfg |
| 129 | cd /home/gerrit/cfg |
| 130 | |
| 131 | ssh-keygen -t rsa -P '' -f ssh_host_rsa_key |
| 132 | ssh-keygen -t dsa -P '' -f ssh_host_dsa_key |
| 133 | |
| 134 | psql -c "UPDATE system_config SET site_path='/home/gerrit/cfg'" reviewdb |
| 135 | ==== |
| 136 | |
| 137 | The SSH keys generated here are used as the host keys for the |
| 138 | internal SSH daemon run by Gerrit. You may wish to backup these |
| 139 | key files to ensure they can be restored in the event of a disaster. |
| 140 | |
| 141 | The private key files (`ssh_host_rsa_key`, `ssh_host_dsa_key`) should |
| 142 | be readable *only* by the account that is executing Gerrit2's web |
| 143 | application container. It is a security risk to make these files |
| 144 | readable by anyone else. |
| 145 | |
| 146 | Create Git Repository Base |
| 147 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 148 | |
| 149 | This directory holds the Git repositories that Gerrit knows about |
| 150 | and can service. Gerrit needs write access to this directory and |
| 151 | any Git repository stored within it. |
| 152 | |
| 153 | ==== |
| 154 | mkdir /srv/git |
| 155 | psql -c "UPDATE system_config SET git_base_path='/srv/git'" reviewdb |
| 156 | ==== |
| 157 | |
| 158 | You may wish to consider also exporting this directory over the |
| 159 | anonymous git:// protocol, as it is more efficient than Gerrit's |
| 160 | internal ssh daemon. See the `git-daemon` documentation for details |
| 161 | on how to configure this if anonymous access is desired. |
| 162 | |
| 163 | * http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html[man git-daemon] |
| 164 | |
| 165 | Futher Configuration |
| 166 | ~~~~~~~~~~~~~~~~~~~~ |
| 167 | |
| 168 | Gerrit2 supports some site-specific customizations. These are |
| 169 | optional and are not required to run a server, but may be desired. |
| 170 | |
| Shawn O. Pearce | f384b44 | 2009-01-10 16:20:56 -0800 | [diff] [blame] | 171 | * link:config-sso.html[Single Sign-On Systems] |
| Shawn O. Pearce | 5a14d66 | 2009-01-23 16:39:51 -0800 | [diff] [blame] | 172 | * link:config-replication.html[Git Replication/Mirroring] |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 173 | * link:config-headerfooter.html[Site Header/Footer] |
| 174 | * link:config-gitweb.html[Gitweb Integration] |
| 175 | * link:config-gerrit.html[Other system_config Settings] |
| 176 | |
| 177 | Application Deployment |
| 178 | ----------------------- |
| 179 | |
| 180 | Jetty |
| 181 | ~~~~~ |
| 182 | |
| 183 | These directions will configure Gerrit as the default web |
| 184 | application, allowing URLs like `http://example.com/4543` to |
| 185 | jump directly to change 4543. |
| 186 | |
| 187 | Download and unzip a release version of Jetty. From here on we |
| 188 | call the unpacked directory `$JETTY_HOME`. |
| 189 | |
| 190 | * http://dist.codehaus.org/jetty/[Jetty Downloads] |
| 191 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 192 | Install the JDBC drivers, using either the ones that come embedded |
| 193 | with Gerrit, or by downloading them yourself from their mirrors: |
| 194 | ==== |
| 195 | java -jar gerrit.war --cat lib/c3p0-0.9.1.2.jar >$JETTY_HOME/lib/plus/c3p0-0.9.1.2.jar |
| 196 | java -jar gerrit.war --cat lib/postgresql-8.3-603.jdbc3.jar >$JETTY_HOME/lib/plus/postgresql-8.3-603.jdbc3.jar |
| 197 | ==== |
| 198 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 199 | Copy Gerrit into the deployment: |
| 200 | ==== |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 201 | java -jar gerrit.war --cat extra/jetty_gerrit.xml >$JETTY_HOME/contexts/gerrit.xml |
| 202 | cp gerrit.war $JETTY_HOME/webapps/gerrit.war |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 203 | |
| 204 | rm -f $JETTY_HOME/context/test.xml |
| 205 | ==== |
| 206 | |
| 207 | Edit `$JETTY_HOME/contexts/gerrit.xml` to correctly configure the |
| Shawn O. Pearce | 92a19d2 | 2009-01-13 13:27:59 -0800 | [diff] [blame] | 208 | database and outgoing SMTP connections, especially the user and |
| 209 | password fields. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 210 | |
| 211 | To start automatically when the system boots, consider a start |
| 212 | script such as the following in `/etc/init.d/gerrit2-jetty` |
| 213 | |
| 214 | ==== |
| 215 | #!/bin/sh |
| 216 | |
| 217 | export JETTY_HOST=127.0.0.1 |
| 218 | export JETTY_PORT=8081 |
| 219 | export JETTY_USER=gerrit2 |
| 220 | export JETTY_PID=/var/run/jetty$JETTY_PORT.pid |
| 221 | export JETTY_HOME=/home/$JETTY_USER/jetty |
| 222 | export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.07/jre |
| 223 | |
| 224 | JAVA_OPTIONS="" |
| 225 | JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.host=$JETTY_HOST" |
| 226 | export JAVA_OPTIONS |
| 227 | |
| 228 | exec $JETTY_HOME/bin/jetty.sh "$@" |
| 229 | ==== |
| 230 | |
| 231 | To deploy on port 80, or to use SSL, you should configure Jetty |
| 232 | to listen on another port, such as 127.0.0.1:8081 (like the start |
| 233 | script above does) and then follow the <<apache2,reverse proxy>> |
| 234 | section below. |
| 235 | |
| 236 | [TIP] |
| 237 | Under Jetty, restarting the web application (e.g. after modifying |
| 238 | `system_config`) is as simple as touching the config file: |
| 239 | `$JETTY_HOME/contexts/gerrit.xml` |
| 240 | |
| 241 | Other Servlet Containers |
| 242 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 243 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 244 | Deploy the `gerrit-*.war` file to your application server as |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 245 | `gerrit.war`. |
| 246 | |
| 247 | Configure the JNDI DataSource `jdbc/ReviewDb` for the Gerrit web |
| 248 | application context to point to the database you just created. |
| 249 | Don't forget to ensure your JNDI configuration can load the |
| 250 | necessary JDBC drivers. |
| 251 | |
| Shawn O. Pearce | 92a19d2 | 2009-01-13 13:27:59 -0800 | [diff] [blame] | 252 | ('Optional') Configure the JNDI name `mail/Outgoing` for the web |
| 253 | application context to be a factory for a `javax.mail.Session`, |
| 254 | with the connection information necessary to send outgoing emails. |
| 255 | You may need to download and install the Java Mail JARs in your |
| 256 | container's classpath. If this is not configured, Gerrit will |
| 257 | function, but will not be able to send email. |
| 258 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 259 | [[apache2]] |
| 260 | Apache2 Reverse Proxy |
| 261 | ~~~~~~~~~~~~~~~~~~~~~ |
| 262 | |
| 263 | Enable the necessary Apache2 modules: |
| 264 | |
| 265 | ==== |
| 266 | a2enmod proxy_http |
| 267 | a2enmod disk_cache ; # optional, but helps performance |
| 268 | ==== |
| 269 | |
| 270 | then setup a VirtualHost to proxy to Gerrit's servlet container, |
| 271 | setting the `ProxyPass` line to use the port number you configured |
| 272 | in your servlet container's configuration: |
| 273 | |
| 274 | ======================================= |
| 275 | <VirtualHost *> |
| 276 | ServerName review.example.com |
| 277 | # |
| 278 | ProxyRequests Off |
| 279 | ProxyVia Off |
| 280 | ProxyPreserveHost On |
| 281 | # |
| 282 | <Proxy *> |
| 283 | Order deny,allow |
| 284 | Allow from all |
| 285 | </Proxy> |
| 286 | ProxyPass / http://127.0.0.1:8081/ |
| 287 | # |
| 288 | <IfModule mod_disk_cache.c> |
| 289 | CacheEnable disk / |
| 290 | CacheIgnoreHeaders Set-Cookie |
| 291 | </IfModule> |
| 292 | </VirtualHost> |
| 293 | ======================================= |
| 294 | |
| 295 | To enable SSL, see the Apache server documentation. |
| 296 | |
| 297 | |
| 298 | Administrator Setup |
| 299 | ------------------- |
| 300 | |
| 301 | Login to Gerrit through the web interface, so that a user account |
| 302 | is initialized for you. |
| 303 | |
| 304 | Add your newly created account to the "Administrators" group, |
| 305 | so that you can manage the site through the web interface: |
| 306 | |
| 307 | ==== |
| 308 | psql reviewdb |
| 309 | INSERT INTO account_group_members |
| 310 | (account_id, group_id) |
| 311 | VALUES ( |
| 312 | (SELECT account_id FROM accounts |
| 313 | WHERE preferred_email='you@example.com'), |
| 314 | (SELECT admin_group_id FROM system_config) |
| 315 | ); |
| 316 | ==== |
| 317 | |
| 318 | Group memberships are cached, so you need to either restart Gerrit, |
| 319 | or try flushing the caches over SSH. |
| 320 | |
| 321 | Since SSH cache flushing requires being in the "Administrators" |
| 322 | group you may run into a chicken-and-egg problem, where you cannot |
| 323 | flush the cache to make yourself an administrator because you are |
| 324 | not yet an administrator. Therefore, restarting the application |
| 325 | is the recommended bootstrap technique. |
| 326 | |
| 327 | To flush the server's caches over SSH, ensure you have an SSH key |
| 328 | (you can add one through the web UI under Settings, SSH Keys), |
| 329 | and then run: |
| 330 | |
| 331 | ==== |
| 332 | ssh -p 29418 you@example.com gerrit flush-caches |
| 333 | ==== |
| 334 | |
| 335 | Project Setup |
| 336 | ------------- |
| 337 | |
| 338 | See link:project-setup.html[Project Setup] for further details on |
| 339 | how to register a project with Gerrit. |